import React from "react";
import axios from "axios";
import {getUrlFor} from "@/services/UrlConfig";
import {formatResult} from "@/services/Utils";


const fetchAllBusNo = async (params: API.PageParams,
                             sort: Record<string, 'ascend'|'descend'|null>,
                             filter: Record<string, React.ReactText[]|null>) => {
  const reqParams = {
    start: params.current,
    size: params.pageSize
  }
  const res = await axios.get(getUrlFor("/bus-no", reqParams))
  return formatResult(res);
}

const addBusNo = async (busNo: Domain.BusNo) => {
  await axios.post(getUrlFor("/bus-no", busNo));
}

const rmBusNo = async (id: number |string| undefined) => {
  await axios.delete(getUrlFor("/bus-no/"+id));
}

const updateBusNo = async (busNo: Domain.BusNo) => {
  await axios.put(getUrlFor("/bus-no/"+busNo.id, busNo));
}


export {fetchAllBusNo, addBusNo, rmBusNo, updateBusNo}
